<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="renderer" content="webkit">
    <link rel="stylesheet" href="../../mdui/css/mdui.min.css">
    <script defer src="../../mdui/js/mdui.min.js"></script>
    <script src="../../js/axios.min.js"></script>
    <script src="../../js/qs.min.js"></script>
    <script src="../../js/common.js"></script>
    <script src="../../js/vue.js"></script>
    <style>
        a {
            color: #ffffff;
            text-decoration: none;
        }
    </style>
</head>
<body class="mdui-theme-primary-indigo mdui-theme-accent-green">

<div class="mdui-container-fluid" id="app">
    <h1 class="mdui-text-color-theme">维修人员</h1>
    <div style="width: auto">
        <table class="mdui-table mdui-table-hoverable">
            <thead>
            <tr>
                <th>姓名</th>
                <th>工号</th>
                <th>电话</th>
                <th>工种</th>
                <th>删除</th>
                <th>修改</th>
            </tr>
            </thead>
            <tbody>
            <tr v-for="(m,index) in maintainers">
                <td>{{m.name}}</td>
                <td>{{m.number }}</td>
                <td>{{m.phone}}</td>
                <td>{{m.type}}</td>
                <td>
                    <button @click="deleteUser(m.id,index)"
                            class="mdui-btn  mdui-color-green-800 mdui-ripple">
                        删除
                    </button>
                </td>
                <td>
                    <button class="mdui-btn mdui-color-green-800 mdui-ripple">
                        <a :href="'edit.html?id='+m.id">修改
                        </a>
                    </button>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>

<script>

    let vm = new Vue({
        el: '#app',
        data: {
            maintainers: [],
        },

        created() {
            this.findmaintainers();
        },
        methods: {
            findmaintainers() {
                let _this = this;
                axios
                    .get("/technician/list")
                    .then(function (res) {
                        _this.maintainers = res.data;
                    })
            },

            deleteUser(id, index) //uid传到后台后台正确删除后 根据index移除数组中对应的数据
            {
                console.log(123)
                let _this = this;
                axios.delete("/technician/deleteTechnician/" + id)
                    .then(function (res) {
                        if (res.data.success) {
                            _this.maintainers.splice(index, 1)
                            mdui.alert("删除成功");
                            mdui.mutation()
                        }
                    })
            },
        },
    })
</script>
</body>
</html>